package org.takinframework.web.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.takinframework.core.util.ApplicationContextUtil;
import org.takinframework.core.util.ResourceUtil;
import org.takinframework.core.util.StringUtil;
import org.takinframework.web.system.entity.SysDepart;
import org.takinframework.web.system.entity.SysFunction;
import org.takinframework.web.system.service.SystemService;

/**
 * WEB端用EL表达式获取属性值
 * @author twg
 *
 */
public class WebUtil {
	
	/**
	 * 获取值
	 * @param name 属性名
	 * @return
	 */
	public static String getSysName(String name){
		return ResourceUtil.getConfig(name);
	}
	/**
	 * 通过用户id,获取组织机构名
	 * @param userId 用户id
	 * @return
	 */
	public static String getDepartNameByUser(String userId){
		SystemService systemService = (SystemService) ApplicationContextUtil.getBean("systemService");
		List<SysDepart> sysDeparts = systemService.findList(SysDepart.class, "methord1", userId);
		if(sysDeparts.size()>0){
			return sysDeparts.get(0).getDepartName();
		}
		return "";
	}
	
	public static List<SysFunction> getSysFunction(){
		
		
		return null;
		
	}
	
	
	
	/**
	 * 获取HTTP请求时的参数信息
	 * @param request
	 * @return
	 */
	public static String getParams(HttpServletRequest request){
		StringBuilder params = new StringBuilder();
		int index = 0;
		for (Object param : request.getParameterMap().keySet()){ 
			params.append((index++ == 0 ? "" : "&") + param + "=");
			params.append(StringUtil.subStringEncode(StringUtil.endsWithIgnoreCase((String)param, "password")
					? "" : request.getParameter((String)param), 100));
		}
		return params.toString();
		
	}
}
